#ifndef __ProducerThread_H__
#define __ProducerThread_H__

#include "Thread.hpp"
#include "TaskQueue.hpp"

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <unistd.h>

#include <iostream>
using std::cout;
using std::endl;

namespace wd
{

class ProducerThread
: public Thread
{
public:
    ProducerThread(TaskQueue & que)
    : _que(que)
    {}

    ~ProducerThread(){
        cout << "~ProducerThread()" << endl;
    }

private:
    void run() override
    {
        int cnt = 20;
        srand(time(NULL));//设置随机数生成的种子
        while(cnt-- > 0) {
            int num = rand() % 100;
            _que.push(num);
            cout << ">>"  << cnt << " produce a num " << num << endl;
            //sleep(1);
        }
    }

private:
    TaskQueue & _que;
};



}//end of namespace wd


#endif

